package cn.tedu.m2;

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Scanner;

/**
 * @Author wy
 * @Date 2021/3/4 9:15
 * @Version 1.0
 */
@Component
public class Producer {
    //RabbitAutoConfiguration
    @Autowired

    //生产者的发送方法 需要手动调用
    private AmqpTemplate t;
    public void send(){
        //自动转成byte[]数组再发送
        while(true){
            System.out.println("输入消息:  ");
            String s=new Scanner(System.in).nextLine();
            t.convertAndSend("task_queue",s);

//            t.convertAndSend("", "task_queue", s, new MessagePostProcessor() {
//                @Override
//                public Message postProcessMessage(Message message) throws AmqpException {
//                    return null;
//                }
//            });
        }

    }
}
